home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 12.0 KB | 397 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Frame.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: M.Boetcher
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Embed.hpp"
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef PROXY_H
- #include "Proxy.h"
- #endif
-
- #ifndef COMMAND_H
- #include "Command.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef SELECT_H
- #include "Select.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWPXYFRM_H
- #include "FWPxyFrm.h"
- #endif
-
- #ifndef FWGROWBX_H
- #include "FWGrowBx.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- // ----- OS Layer Includes -----
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWMNUBAR_H
- #include "FWMnuBar.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- //========================================================================================
- // Runtime information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfembed
- #endif
-
- FW_DEFINE_AUTO(CEmbedFrame)
-
- //========================================================================================
- // Constant
- //========================================================================================
-
- const FW_Fixed kBorder = FW_IntToFixed(15);
- const FW_Fixed kHalfBorder = FW_IntToFixed(8);
-
- //========================================================================================
- // CLASS CEmbedFrame
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::CEmbedFrame
- //----------------------------------------------------------------------------------------
-
- CEmbedFrame::CEmbedFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- CEmbedPart* part,
- CEmbedContent* content) :
- FW_CEmbeddingFrame(ev, odFrame, presentation, part),
- FW_MDraggableFrame(ev, this),
- FW_MDroppableFrame(ev, this),
- fPart(part),
- fContent(content)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::~CEmbedFrame
- //----------------------------------------------------------------------------------------
-
- CEmbedFrame::~CEmbedFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::Draw
- //----------------------------------------------------------------------------------------
-
- void CEmbedFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- FW_CViewContext vc(ev, this, odFacet, invalidShape);
-
- FW_CRectShape::RenderRect(vc, GetBounds(ev), FW_kFill, FW_kRGBBlue);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::Draw
- //----------------------------------------------------------------------------------------
-
- void CEmbedFrame::CreateSubViews(Environment* ev)
- {
- // ----- Create a GrowBox only in root frame
- // Note: You do not need CreateSubViews if the views are defined in resources.
- // See the Container or Form samples
-
- if (this->IsRoot(ev))
- {
- FW_CRect frameRect = GetBounds(ev);
- FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
- frameRect.right -= sbSize.x;
- frameRect.bottom -= sbSize.y;
-
- FW_CGrowBox* growBox = new FW_CGrowBox(ev, this, 0, frameRect.BotRight());
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::CanAcceptDrop
- //----------------------------------------------------------------------------------------
- // As an embedding frame I can accept anything
-
- ODDragResult CEmbedFrame::CanAcceptDrop(Environment *ev, ODDragItemIterator* dragInfo)
- {
- return TRUE;
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedFrame::DoAdjustMenus
- //---------------------------------------------------------------------------------------
-
- FW_Boolean CEmbedFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- if (hasMenuFocus)
- {
- // Check clipboard for a part to paste
- menuBar->EnableCommand(ev, kODCommandPaste, HasPropertyOnClipboard(ev, kODPropContentFrame, NULL));
-
- // If an embedded part is selected, change Copy menu item to "Copy Part"
- if (GetPresentation(ev)->GetSelection(ev)->IsEmpty(ev))
- menuBar->SetItemString(ev, kODCommandCopy, FW_CString32("Copy"));
- else
- menuBar->SetItemString(ev, kODCommandCopy, FW_CString32("Copy Part"));
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::MakeFrameShape
- //----------------------------------------------------------------------------------------
- // Returns a new shape equals to my frame shape inset by eight pixels. Otherwise I can't drop
- // anything
-
- ODShape* CEmbedFrame::MakeFrameShape(Environment* ev)
- {
- FW_CRect bounds = GetBounds(ev);
- bounds.Inset(kBorder);
- bounds.Place(FW_kFixed0, FW_kFixed0); // Frame shape always zero based
- return ::FW_NewODShape(ev, bounds);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::CreateOneEmbeddedFacet
- //----------------------------------------------------------------------------------------
-
- ODFacet* CEmbedFrame::CreateOneEmbeddedFacet(Environment* ev,
- ODFacet* embeddingFacet,
- ODFrame* embeddedFrame,
- ODFacet* sibling,
- const FW_CRect& clipRect)
- {
- FW_CAcquiredODTransform externalTransform = ::FW_NewODTransform(ev, FW_CPoint(kBorder, kBorder));
- FW_CAcquiredODShape clipShape = ::FW_NewODShape(ev, clipRect);
-
- return embeddingFacet->CreateEmbeddedFacet(ev,
- embeddedFrame,
- clipShape,
- externalTransform,
- NULL, // Canvas
- NULL, // biasCanvas
- sibling, // siblingFacet
- kODFrameInFront);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::EmbeddedFacetBounds
- //----------------------------------------------------------------------------------------
-
- void CEmbedFrame::EmbeddedFacetBounds(Environment* ev, FW_CRect* clipRects)
- {
- FW_CRect bounds = GetBounds(ev);
- bounds.Place(FW_kFixed0, FW_kFixed0);
- bounds.Inset(kBorder);
-
- FW_CRect embeddedBounds = bounds;
- embeddedBounds.Place(FW_kFixed0, FW_kFixed0);
-
- FW_CPoint embeddedMiddle(FW_Half(embeddedBounds.left + embeddedBounds.right), FW_Half(embeddedBounds.top + embeddedBounds.bottom));
-
- FW_CPoint middle(FW_Half(bounds.left + bounds.right), FW_Half(bounds.top + bounds.bottom));
-
- clipRects[0].Set(FW_kFixed0, FW_kFixed0, embeddedMiddle.x - kHalfBorder, embeddedMiddle.y - kHalfBorder);
- clipRects[1].Set(embeddedMiddle.x + kHalfBorder, FW_kFixed0, embeddedBounds.right, embeddedMiddle.y - kHalfBorder);
- clipRects[2].Set(FW_kFixed0, embeddedMiddle.y + kHalfBorder, embeddedMiddle.x - kHalfBorder, embeddedBounds.bottom);
- clipRects[3].Set(embeddedMiddle.x + kHalfBorder, embeddedMiddle.y + kHalfBorder, embeddedBounds.right, embeddedBounds.bottom);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::CreateEmbeddedFacet
- //----------------------------------------------------------------------------------------
-
- ODFacet* CEmbedFrame::CreateEmbeddedFacet(Environment* ev,
- ODFacet* embeddingFacet,
- FW_MProxy* proxy,
- ODFrame* embeddedFrame,
- ODShape* proposedClipShape)
- {
- FW_CRect bounds = GetBounds(ev);
- bounds.Place(FW_kFixed0, FW_kFixed0);
- bounds.Inset(kBorder);
-
- FW_CRect embeddedBounds = bounds;
- embeddedBounds.Place(FW_kFixed0, FW_kFixed0);
-
- if (fPart->FacetNumber() == cOneFacet)
- {
- return CreateOneEmbeddedFacet(ev, embeddingFacet, embeddedFrame, NULL, embeddedBounds);
- }
- else
- {
- FW_CRect clipRects[4];
- EmbeddedFacetBounds(ev, clipRects);
-
- ODFacet* siblingFacet = NULL;
-
- siblingFacet = CreateOneEmbeddedFacet(ev,
- embeddingFacet,
- embeddedFrame,
- siblingFacet,
- clipRects[0]);
- CreateOneEmbeddedFacet(ev,
- embeddingFacet,
- embeddedFrame,
- siblingFacet,
- clipRects[1]);
- CreateOneEmbeddedFacet(ev,
- embeddingFacet,
- embeddedFrame,
- siblingFacet,
- clipRects[2]);
- return CreateOneEmbeddedFacet(ev,
- embeddingFacet,
- embeddedFrame,
- siblingFacet,
- clipRects[3]);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::FrameShapeChanged
- //----------------------------------------------------------------------------------------
- // Change the frame shape of the embedded frame to be the same as mine minus a border
-
- void CEmbedFrame::FrameShapeChanged(Environment* ev)
- {
- // Must call inherited so our "view" superclass gets adjusted.
- FW_CFrame::FrameShapeChanged (ev);
-
- CEmbedProxy* proxy = fContent->GetProxy();
- if (proxy != NULL)
- {
- FW_CAcquiredODFrame embeddedFrame = proxy->AcquireEmbeddedFrame(ev, this);
-
- FW_CAcquiredODShape frameShape = MakeFrameShape(ev);
- embeddedFrame->ChangeFrameShape(ev, frameShape, NULL);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::NewClipboardCommand
- //----------------------------------------------------------------------------------------
-
- FW_CClipboardCommand* CEmbedFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
- {
- FW_Boolean undoAble = TRUE;
- if (commandID == kODCommandPasteAs)
- undoAble = FALSE;
-
- return FW_NEW(CEmbedEditCommand, (ev,
- commandID,
- fContent,
- this,
- GetPresentation(ev)->GetSelection(ev),
- undoAble));
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::NewDropCommand
- //----------------------------------------------------------------------------------------
-
- FW_CDropCommand* CEmbedFrame::NewDropCommand(Environment* ev,
- FW_CFrame* frame,
- ODDragItemIterator* dropInfo,
- ODFacet* odFacet,
- const FW_CPoint& dropPoint)
- {
- return FW_NEW(CEmbedDropCommand, (ev, fContent, this, dropInfo, odFacet, dropPoint));
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::NewDragCommand
- //----------------------------------------------------------------------------------------
-
- FW_CDragCommand* CEmbedFrame::NewDragCommand(Environment *ev, FW_CFrame* theFrame, const FW_CMouseEvent& theMouseEvent)
- {
- FW_UNUSED(theMouseEvent);
-
- return FW_NEW(CEmbedDragCommand, (ev, fContent, this, (CEmbedSelection*)GetPresentation(ev)->GetSelection(ev)));
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::NewInsertCommand
- //----------------------------------------------------------------------------------------
- FW_CInsertCommand* CEmbedFrame::NewInsertCommand(Environment* ev, const FW_PFileSpecification& fileSpec)
- {
- return FW_NEW(CEmbedInsertCommand, (ev,
- this,
- fileSpec,
- fContent));
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::DoMouseDownInEmbeddedFrameBorder
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CEmbedFrame::DoMouseDownInEmbeddedFrameBorder(Environment *ev, const FW_CBorderMouseEvent& theBorderMouseEvent)
- {
- Drag(ev, theBorderMouseEvent);
-
- return TRUE;
- }
-
-